<!--#include file="./header.inc"-->
<%

select case aq
	'custom
	case "save" 		: 	call save
	case "edit" 		: 	call edit
	case "delete" 		: 	call delete
	case else 			: 	call index
end select

call db.close()

function index()
    sql = "select id,customTag,customContent from cj_custom Order By id desc"
    temp = db.arrayData(sql, page, rows)
    infoTotal = temp(0)
    data = temp(1)
    %><!--#include file="./view/custom.index.html"--><%
end function

function edit()
	data = array("", "")
	if iid > 0 then
		set rs = db.exec("select customTag,customContent from cj_custom where id=" & iid, 1)
		if rs.eof then admin.message "标签ID不存在！"
		data = rs
		set rs = nothing
	end if
	%><!--#include file="./view/custom.edit.html"--><%
end function

function save()
	dim customTag, customContent, oldName
	customTag = admin.filter(request.form("customTag"))
	customContent = trim(request.form("customContent"))
	if len(customTag) = 0 then admin.message "标签名称不能为空！"
	if len(customContent) = 0 then admin.message "标签内容不能为空！"
	oldName = ""
	if iid > 0 then
		set rs = db.exec("select * from cj_custom where id=" & iid, 3)
		if rs.eof then admin.message "标签ID" & iid & "不存在！"
		if customTag <> rs("customTag") then
            oldName = rs("customTag")
		end if
	else
		set rs = db.exec("select * from cj_custom", 3)
		rs.AddNew
	end if
	rs("customTag") = customTag
	rs("customContent") = customContent
	rs.update
	rs.close : set rs = nothing
	app.viewFileWrite "my_" & lcase(customTag), customContent
	if oldName <> "" then
	    app.deleteFile root & cacheDir & "/view/my_" & oldName & viewExt
	end if
	if iid > 0 then
		admin.back "修改成功！", "返回列表", "?q=index"
	else
		admin.back "添加成功！", "继续添加", "?q=edit"
	end if
end function

function delete()
	call db.exec("Delete from cj_custom where id in(" & batchId & ")", 1)
	admin.updateWebAllData()
	app.json "删除成功！", 0
end function

%>